#ifndef __DATA_GLOBAL__H__
#define __DATA_GLOBAL__H__


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
#include <pthread.h>
#include <termios.h>
#include <syscall.h>

#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/msg.h>
#include <sys/sem.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <linux/fs.h>
#include <linux/ioctl.h>
#include <stdint.h>
#include <unistd.h>
#include <errno.h>
#include <linux/input.h>


#define MONITOR_NUM   1
#define QUEUE_MSG_LEN  32

//设备文件
#define		ZIGBEE_DEV 		 "/dev/ttyUSB0"
#define		BEEPER_DEV 		 "/dev/fsbeeper0"
#define		LED_DEV    		 "/dev/led0"
#define		MPU6050_DEV    	 "/dev/fsmpu60500"


//类型重定义
typedef  unsigned char uint8_t;
typedef  unsigned short uint16_t;
typedef  unsigned int uint32_t;

//Zigbee上传数据
struct makeru_zigbee_info{
	//标识位: 'm' 's' 'm'  makeru-security-monitor
	uint8_t head[3];
	//数据类型  'z'---zigbee  'a'---a9   
	uint8_t type;
	
	//温度
	float temperature;
	//湿度下限
	float humidityMIN;
	//湿度上限   
	float humidityMAX; 
	
	//湿度
	float humidity;
	//温度下限  
	float tempMIN;
	//温度上限
	float tempMAX; 

	//保留扩展位，默认填充0
	uint32_t reserved[2]; 
};

//A9平台上传数据
struct makeru_a9_info{
	//标识位: 'm' 's' 'm'  makeru-security-monitor  
	uint8_t head[3];
	//数据类型  'z'---zigbee  'a'---a9 
	uint8_t type;	 

	//陀螺仪数据
	short gyrox;   
	short gyroy;
	short gyroz;

	//加速计数据
	short  aacx;  
	short  aacy;
	short aacz;

	//保留扩展位，默认填充0
	uint32_t reserved[2]; 
};


//平台上所有上传数据
struct makeru_env_data{
	struct makeru_a9_info       a9_info;    
	struct makeru_zigbee_info   zigbee_info;
	//保留扩展位，默认填充0
	uint32_t reserved[2]; 
};

//所有监控区域上传的信息结构体
struct env_info_client_addr
{
	struct makeru_env_data  monitor_no[MONITOR_NUM];	//数组  老家---新家
}__attribute__((aligned (1))); 

//共享内存结构体
struct shm_addr
{
	char shm_status;   //shm_status可以等于home_id，用来区分共享内存数据
	struct env_info_client_addr  sm_all_env_info;
};

//消息队列结构体（下发数据）
struct msg
{
	long type;//从消息队列接收消息时用于判断的消息类型
	long msgtype;//具体的消息类型
	unsigned char text[QUEUE_MSG_LEN];//消息正文
};



//处理CGI进程下发的请求（遍历消息队列）
void *pthread_client_request (void *arg);
//刷新上传共享内存数据线程 （刷新共享内存环境数据供CGI进程使用）
void *pthread_refresh(void *arg);
//led灯控制线程         
void *pthread_led(void *arg);
//Seg数码管控制线程         
void *pthread_seg(void *arg);                     
//蜂鸣器控制线程           
void *pthread_buzzer(void *arg);
//Zigbee风扇控制线程           
void *pthread_fan(void *arg);



#endif 


